home *** CD-ROM | disk | FTP | other *** search
- #include "Notify.h"
-
-
- void HandleCreate( FWData theFWData )
- {
- DoMakeAlias( theFWData );
- }
-
-
- OSErr DoMakeAlias( FWData theData )
- {
- long theParID, raFolderID;
- short fileRef, theVRefNum;
- AliasHandle alias;
- FInfo theFInfo, targetFInfo;
- FSSpec aliasSpec;
- FSSpecPtr theFSSpec;
- OSErr fileError;
-
- LogResult( theData );
-
- fileError = DoFindOneFolder( RECENT_ADDS_NAME_STRING, kAppleMenuFolderType, &raFolderID );
-
- if ( fileError != noErr ) {
- //DebugStr( "\pUnable to locate folder." );
- return fileError;
- }
-
- if ( raFolderID == theData.theParID ) {
- //DebugStr( "\pFolders match." );
- return fileError;
- }
-
- FSMakeFSSpec( theData.theVRefNum, theData.theParID, theData.theString, theFSSpec );
-
- fileError = NewAlias( 0L, theFSSpec, &alias );
- if ( fileError )
- return( fileError );
-
- fileError = FSpGetFInfo( theFSSpec, &targetFInfo );
-
- if ( targetFInfo.fdType == APPL_RES_TYPE )
- targetFInfo.fdType = ADRP_RES_TYPE;
-
- if ( theFSSpec->name[ 0 ] > MAX_NAME_SIZE )
- theFSSpec->name[ 0 ] = MAX_NAME_SIZE - SUFFIX_SIZE;
-
- BlockMove( theFSSpec->name, aliasSpec.name, theFSSpec->name[ 0 ] + 1 );
- fileError = FindFolder( kOnSystemDisk, kAppleMenuFolderType, kDontCreateFolder, &aliasSpec.vRefNum, &aliasSpec.parID );
-
- aliasSpec.parID = raFolderID;
-
- fileError = FSpRstFLock( &aliasSpec );
- if ( !( ( fileError == fnfErr ) || ( fileError == noErr ) ) )
- return( fileError );
-
- if ( fileError == noErr ) {
- fileError = FSpDelete( &aliasSpec );
- if ( fileError )
- return( fileError );
- }
-
- FSpCreateResFile( &aliasSpec, targetFInfo.fdCreator, targetFInfo.fdType, smSystemScript );
- fileError = ResError();
- if ( fileError )
- return( fileError );
-
- fileError = FSpGetFInfo( &aliasSpec, &theFInfo );
- if ( fileError )
- return( fileError );
-
- theFInfo.fdFlags = theFInfo.fdFlags | 0x8000;
- FSpSetFInfo( &aliasSpec, &theFInfo );
-
- fileRef = FSpOpenResFile( &aliasSpec, fsCurPerm );
- if ( fileRef == BAD_FILE_REF_NUM ) {
- fileError = ResError();
- return( fileError );
- }
-
- AddResource( ( Handle )alias, rAliasType, 0, "\p" );
-
- fileError = ResError();
- if ( fileError )
- return( fileError );
-
- CloseResFile( fileRef );
-
- // fileError = FlushVol( NIL, aliasSpec.vRefNum );
-
- return( fileError );
- }
-
-
- OSErr DoFindOneFolder(
- Str255 theName,
- OSType theFolderType,
- long *theFolderID )
- {
- FSSpec theSpec;
- OSErr fileError;
- CInfoPBPtr thePBPtr;
-
- thePBPtr = ( CInfoPBPtr )NewPtrClear( sizeof( CInfoPBRec ) );
-
- *theFolderID = NIL;
-
- fileError = FindFolder( kOnSystemDisk, theFolderType, kCreateFolder, &theSpec.vRefNum, &theSpec.parID );
-
- if ( fileError == noErr ) {
- if ( thePBPtr != NIL ) {
- thePBPtr->dirInfo.ioCompletion = 0L;
- thePBPtr->dirInfo.ioNamePtr = theName;
- thePBPtr->dirInfo.ioVRefNum = theSpec.vRefNum;
- thePBPtr->dirInfo.ioDrDirID = theSpec.parID;
- thePBPtr->dirInfo.ioFDirIndex = 0;
-
- fileError = PBGetCatInfo( thePBPtr, true );
-
- while ( thePBPtr->dirInfo.ioResult == 1 ) {
- ;
- }
-
- if ( ( thePBPtr->dirInfo.ioResult == noErr ) && ( fileError == noErr ) && ( thePBPtr->dirInfo.ioFlAttrib & 0x0010 ) )
- *theFolderID = thePBPtr->dirInfo.ioDrDirID;
- }
- else
- fileError = BAD_FILE_REF_NUM;
- }
-
- if ( thePBPtr != NIL )
- DisposePtr( ( Ptr )thePBPtr );
-
- return( fileError );
- }
-